<?php
namespace waf\server;

use \waf\Waf;
use \waf\log\Log;
use \waf\server\BaseServer;
use \Yaf;

class HttpServer extends BaseServer
{
    public function init()
    {
        Log::logSystem("in", __FILE__, __LINE__, __FUNCTION__);
        $this->strServerType = 'http';
        parent::init();
        Log::logSystem("out", __FILE__, __LINE__, __FUNCTION__);
    }

    public function onRequest($objRequest, $objResponse)
    {
        Log::logSystem("in:".print_r($objRequest->server['request_uri'], true), __FILE__, __LINE__, __FUNCTION__);
        ob_start();
        try {
            $requestObj = new \Yaf_Request_Http($objRequest->server['request_uri']);
            $this->objYaf->getDispatcher()->dispatch($requestObj);
        } catch (\Yaf_Exception $e) {
            Log::logError("yaf_exception:".print_r($e, true), __FILE__, __LINE__, __FUNCTION__);
        }
        $result = ob_get_contents();
        ob_end_clean();
        $objResponse->end($result);
    }
}
?>